package com.example.ui;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.Timer;
import java.util.TimerTask;

public class Frame extends AppCompatActivity {
    private FrameLayout frameLayout=null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame);
        final ImageView img1=(ImageView) findViewById(R.id.p_1);
        final ImageView img2=(ImageView) findViewById(R.id.p_2);
        final ImageView img3=(ImageView) findViewById(R.id.p_3);
        final ImageView img4=(ImageView) findViewById(R.id.p_4);
        final ImageView img5=(ImageView) findViewById(R.id.p_5);

        final Button btn1 = (Button) findViewById(R.id.button_frame_back);
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent_to_main =(Intent) new Intent(Frame.this,MainActivity.class);
                startActivity(intent_to_main);
            }
        });

        Timer timer=new Timer();
        final Handler handler=new Handler(){
            @Override
            public void handleMessage(Message msg) {
                switch(msg.what){

                    case 1:
                        img5.setVisibility(View.INVISIBLE);
                        img1.setVisibility(View.VISIBLE);
                        break;
                    case 2:
                        img1.setVisibility(View.INVISIBLE);
                        img2.setVisibility(View.VISIBLE);
                        break;
                    case 3:
                        img2.setVisibility(View.INVISIBLE);
                        img3.setVisibility(View.VISIBLE);
                        break;
                    case 4:
                        img3.setVisibility(View.INVISIBLE);
                        img4.setVisibility(View.VISIBLE);
                        break;
                    case 5:
                        img4.setVisibility(View.INVISIBLE);
                        img5.setVisibility(View.VISIBLE);
                        break;
                    default:System.out.println("哈哈,没有图片");break;
                }
            }

        };
        timer.scheduleAtFixedRate(new TimerTask() {
            int i=0;
            @Override
            public void run() {
                i++;
                System.out.println(i);
                Message msg=new Message();
                msg.what=i;
                i%=5;
                handler.sendMessage(msg);
            }

        },1000,1000);
    }

}